<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta charset="UTF-8">
    <title>Axios</title>
</head>
<body>
<div id="app">

    <input type="text" v-model="inputname">
    <input type="button" value="查看" @click="Username">
    <p>{{res}}</p>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
    var vm = new Vue({
        el: "#app",
        data: {
            inputname: null,
            res: "用户未注册",
            name2: "null"
        },
        methods: {
            Username:function() {
                var that=this;
                axios.get('http://localhost:8081/vue/username').then(
                    function(response) {
                        that.name2=response.data
                        that.res="用户未注册";
                        for(n in that.name2) {
                            console.log(that.name2[n])
                            if(that.name2[n]==that.inputname)
                            {
                                that.res="用户已注册";
                                break;
                            }
                        }
                    },function(error) {
                    }
                )
            }
        },
        watch: {
            inputname(){
                this.Username();
            }
        },
        created(){
           this.Username();
        }
    });
</script>
</body>
</html>
